import qiniu

# 七牛云的可以
access_key = 'XtjhDnqIPSU6hOcT1S2qEVyOPYvRjhjSHPfl78Nn'
secret_key = 'RevktLFcf_X58d-YJPRUz7rXFHPfcRIOJlNJf6qO'
bucket_name = 'itcast'


def send_pic(data):
    # 设置你的登录信息key
    q = qiniu.Auth(access_key, secret_key)
    # 设置存储的仓库名称
    token = q.upload_token(bucket_name)
    # 七牛的返回值
    # None 为none会返回一个key 用来标识这个图片的唯一性 1.jpg
    # data 就是外部传递过来图片或者是文件信息
    ret, info = qiniu.put_data(token, None, data)
    print(ret, info)
    return ret


# 测试上传图片
if __name__ == '__main__':
    file = input('上传一张图片路径')
    with open(file, 'rb') as f:
        send_pic(f.read())
